<template>
    <div class="singer-song">
        <div class="list">
            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
                <div v-for="(item, index) in list" :key="index" :title="item" class="song">
                    <h3>{{ item.title }}</h3>
                    <div class="singers">
                        <span v-for="(singer, index) in item.singer" :key="singer.id">
                            {{ singer.name }}
                            <span v-show="index != item.singer.length - 1">/</span>
                        </span>
                        <span v-show="item.album.name">
                            <span>·</span>
                            <span>{{ item.album.name }}</span>
                        </span>
                        <span v-show="item.album.subtitle">
                            <span>·</span>
                            <span>{{ item.album.subtitle }}</span>
                        </span>
                    </div>
                </div>
            </van-list>
        </div>
    </div>
</template>
<script>
export default {
    props: ["singerId"],
    data() {
        return {
            song: {
                album: "",//专辑
                name: "",//歌曲
                singer: "",//歌手
            },
            list: [],//vant的list列表数据
            loading: false,
            finished: false,
            page: 1,//获取api数据的页码
        }
    },
    created() {
        this.getData(1, 30)
    },
    methods: {
        getData() {
            this.$request(
                "get",
                "/singer/songs?singermid=" + this.singerId + "&page=" + this.page + "&num=30"
            ).then((res) => {
                console.log(res)
                //res.data.list中是分页获取的数据，30个，把这个数据添加到vant的list列表数据中
                this.list = this.list.concat(res.data.list);
                //加载状态结束
                this.loading = false;
                //页码自动加1
                this.page++;
                //数据全部加载完成（如果页码加1之后获取的data,list的长度为0，代表数据加载完成，没有数据）
                if (res.data.list.length == 0) {
                    this.finished = true;
                }
            })
        },
        onLoad() {
            setTimeout(() => {
                this.getData();//调用获取分页数据的方法
                this.loading = true;//正在加载
            }, 1000)
        }
    }
}
</script>
<style scoped>
.header>img {
    width: 50%;
    border-radius: 1rem;
}

.nick {
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
}

.nick>img {
    width: 1.5rem;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.nick>span {
    height: 2rem;
    /* display: inline-block; */
    /* vertical-align: middle; */
    font-size: 0.8rem;
    line-height: 2rem;
}

.header>span {
    font-size: 0.9rem;
}

.song {
    margin-bottom: 1rem;
}

.song>h3 {
    text-align: left;
    font-size: 1rem;
    padding: 0 2rem;
    margin: 0;
}

.singers {
    text-align: left;
    padding: 0 2rem;
}

.singers span {
    font-size: 0.8rem;
    color: gray;
}

.singers>span:nth-last-child(1)>span:nth-child(1) {
    margin: 0 0.3rem;
    font-weight: 900;
    color: red;
}

.singers>span:nth-last-child(2)>span:nth-child(1) {
    margin: 0 0.3rem;
    font-weight: 900;
    color: red;
}
</style>